'''
Created on Apr 16, 2012
TC ID: Ecom_5014
Des: Kiem thu chuc nang tim kiem mot User
@author: lavang
'''
import unittest
from Functions.globalFunc import readData, preCondition, endCondition
from Functions.loginPageFunc import login
from Functions.usersFunc import clickOnUsers, searchUser,\
     isUserSearch
import time
from HTMLTestRunner import HTMLTestRunner

username = readData("username")
password = readData("password")
tm_user=readData("users")

class Ecom_5014(unittest.TestCase):


    def setUp(self):
        preCondition(self)

    def test_Ecom_5014(self):
        print "Buoc 1: Dang nhap vao website"
        login(self,username,password)
        
        print "Buoc 2: Click vao Users"
        clickOnUsers(self)
        
        print "Buoc 3: Nhap ten user da co vao o filter"
        time.sleep(2)
        searchUser(self,tm_user)
        
        print "Buoc 4: Kiem tra User co ton tai hay khong"
        self.assertTrue(isUserSearch(self,tm_user), "Failed!:User khong ton tai")
        print "Passed: User ton tai"
    
    def tearDown(self):
        endCondition(self)
        

if __name__ == "__main__":
    #import sys;sys.argv = ['', 'Test.testName']
    testSuite = unittest.TestSuite()
    suite = unittest.TestLoader().loadTestsFromTestCase(Ecom_5014)
    dateTime = time.strftime('%Y%m%d_%H_%M_%S')
    buf = file("../../Report/TestResults" + "_" + dateTime + ".html",'wb')
    runner = HTMLTestRunner(
                    stream=buf,
                    title='Test Results',
                    description='Kiem thu chuc nang tim kiem mot User'
                    )
    runner.run(suite)